package com.allqj.sfx.ddd.member.infrastructure.repository;

import com.allqj.sfx.ddd.member.domain.entity.admin.Tenant;
import com.allqj.sfx.ddd.member.domain.repository.TenantRepository;
import com.allqj.sfx.ddd.member.infrastructure.converter.TenantConverter;
import com.allqj.sfx.ddd.member.infrastructure.dao.TenantDAO;
import com.allqj.sfx.ddd.member.infrastructure.po.TenantDO;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author sjw
 * @className TenantRepositoryImpl
 * @date 2022/7/28 17:09
 * @description: TenantRepository实现
 * Repository接口定义位于domain层
 * Repository接口具体实现位于infrastructure层
 * 与底层db解耦
 */
@Repository
public class TenantRepositoryImpl implements TenantRepository {

    private final TenantDAO tenantDAO;

    public TenantRepositoryImpl(TenantDAO tenantDAO) {
        this.tenantDAO = tenantDAO;
    }

    @Override
    public List<Tenant> tenants() {
        List<TenantDO> tenantDOS = tenantDAO.findAllByIsdeleteFalse();
        if (tenantDOS == null)
            return null;
        return tenantDOS.stream().map(TenantConverter.INSTANCE::do2Entity).collect(Collectors.toList());
    }
}
